const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/db');

const Resume = sequelize.define('Resume', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true
  },
  userId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    references: {
      model: 'Users',
      key: 'id'
    }
  },
  template: {
    type: DataTypes.STRING,
    allowNull: false
  },
  basicInfo: {
    type: DataTypes.JSON,
    defaultValue: {
      name: '',
      title: '',
      contact: '',
      email: '',
      location: ''
    }
  },
  education: {
    type: DataTypes.JSON,
    defaultValue: []
  },
  experience: {
    type: DataTypes.JSON,
    defaultValue: []
  },
  skills: {
    type: DataTypes.JSON,
    defaultValue: []
  },
  projects: {
    type: DataTypes.JSON,
    defaultValue: []
  }
});

// 建立与 User 模型的关联
Resume.associate = (models) => {
  Resume.belongsTo(models.User, {
    foreignKey: 'userId',
    as: 'user'
  });
};

module.exports = Resume; 